<?php
/**
 * 前台基类控制器
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/12/10
 * Time: 21:35
 */

namespace app\common\controller;

use think\Controller;

class HomeBase extends Controller
{
    /**
     * 每页显示条数
     * @var int
     */
    public $pageSize = 15;

    /**
     * 构造方法
     * HomeBase constructor.
     */
    public function __construct()
    {
        parent::__construct();

        //主菜单
        $this->getMainNav();

        //友情连接
        $this->getFriendlyLinks();

        $title       = '';
        $keywords    = '为家乡代言';
        $description = '为家乡代言';

        $this->setSEOInfo($title, $keywords, $description);
//        if (APP_DEBUG) {
//            $whoops = new \Whoops\Run;
//            $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
//            $whoops->register();
//        }

        $videoList = [
            ['id' => 1, 'name' => '环合川骑行', 'video' => 'http://player.youku.com/player.php/sid/XMzg5MzU5OTg4/v.swf'],
            ['id' => 2, 'name' => '再访有缘', 'video' => 'http://player.youku.com/player.php/sid/XMzY4NzE4MjU2/v.swf'],
            ['id' => 3, 'name' => '有缘再聚', 'video' => 'http://player.youku.com/player.php/sid/XNTI1MDg4MTEy/v.swf'],
        ];
        $this->assign('videoList', $videoList);
    }

    /**
     * 主菜单
     */
    public function getMainNav()
    {
        //主菜单
        $mainNav = [
            ['name' => '首页', 'url' => '/'],
            ['name' => '食材', 'url' => url('@index/lists/index', 'id=1')],
            ['name' => '美景', 'url' => url('@index/lists/index', 'id=2')],
            ['name' => '旅行', 'url' => url('@index/travel/index')],
            ['name' => '购物', 'url' => '/shopping.html'],
            ['name' => '关于我', 'url' => '/about.html'],
        ];
        foreach ($mainNav as & $nav) {
            $nav['active'] = '';
            if (in_array($nav['url'], [$this->request->url()])) {
                $nav['active'] = 'class="active"';
            }
        }
        unset($nav);
        $this->assign('mainNav', $mainNav);
    }

    /**
     * 友情连接
     */
    public function getFriendlyLinks()
    {
        $friendlyLinks = [
            ['name' => '大地吧', 'url' => 'http://www.dadiba.net'],
            ['name' => '百度', 'url' => 'https://www.baidu.com'],
            ['name' => 'Bootstrap', 'url' => 'http://www.bootcss.com/'],
            ['name' => 'Thinkphp', 'url' => 'http://www.thinkphp.cn/'],
            ['name' => '味分享', 'url' => 'http://www.liangmlk.cn/'],
        ];
        $this->assign('friendlyLinks', $friendlyLinks);
    }

    /**
     * 设置优化信息
     * @param string $title 标题
     * @param string $Keywords 关键字
     * @param string $desc 描述
     */
    public function setSEOInfo($title = '', $Keywords = '', $desc = '')
    {
        $this->assign('title', $title);
        $this->assign('keywords', $Keywords);
        $this->assign('description', $desc);
    }

    /**
     * 设置面包屑
     * @param $title
     * @param $category
     */
    public function setCrumbs($title, $category)
    {

    }

    /**
     * 空操作
     * @param $name
     */
    public function _empty($name)
    {
        $this->redirect('Index/index');
    }
}